package com.ffyc.resale.web;

import com.ffyc.resale.model.ForumComment;
import com.ffyc.resale.model.Result;
import com.ffyc.resale.service.ForumCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


// 帖子评论控制层
@RestController
@RequestMapping("/api/forumComment")
public class ForumCommentController {

    @Autowired
    ForumCommentService forumCommentService;


    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody ForumComment forumComment,@RequestHeader( "userToken") String userToken) {
        forumCommentService.add(forumComment,userToken);
        return new Result(200,"操作成功",null);
    }



    @DeleteMapping("/deepDelete/{id}")
    public Result deepDelete(@PathVariable Integer id) {
        forumCommentService.deepDelete(id);
        return new Result(200,"删除成功",null);
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        ForumComment forumComment = forumCommentService.selectById(id);
        return new Result(200,"查询成功",forumComment);
    }


    /**
     * 查询前台评论列表
     */
    @GetMapping("/selectTree")
    public Result selectTree( Integer fid) {
        List<ForumComment> list = forumCommentService.selectTree(fid);
        return new Result(200,"查询成功",list);
    }

    /**
     * 查询前台评论数量
     */
    @GetMapping("/selectCount")
    public Result selectCount( Integer fid) {
        Integer count = forumCommentService.selectCount(fid);
        return new Result(200,"查询成功",count);
    }
}
